package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.OperationProcessDto;
import com.pureut.production.service.OperationProcessService;
import com.pureut.production.domain.vo.OperationProcessVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工艺流程控制层
 * @author: CM
 * @date: 2023/2/8  14:52
 */
@RestController
@RequestMapping("/process")
public class OperationProcessController extends BaseController {

    @Resource
    private OperationProcessService operationProcessService;

    /**
     * 工艺流程新增
     */
    @RequiresPermissions("productionTube:processmage:processtech:add")
    @Log(title = "新增工艺流程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody OperationProcessVo operationProcessVo) {
        return toAjax(operationProcessService.add(operationProcessVo));
    }

    /**
     * 工艺流程修改
     */
    @RequiresPermissions("productionTube:processmage:processtech:edit")
    @Log(title = "修改工艺流程", businessType = BusinessType.INSERT)
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody OperationProcessVo operationProcessVo) {
        return toAjax(operationProcessService.edit(operationProcessVo));
    }

    /**
     * 工序信息删除
     */
    @RequiresPermissions("productionTube:processmage:processtech:remove")
    @Log(title = "工艺流程删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable("ids") String ids) {
        return toAjax(operationProcessService.remove(ids));
    }

    /**
     * 工序信息列表查询
     */
    @RequiresPermissions("productionTube:processmage:processtech:list")
    @GetMapping("/list")
    public TableDataInfo getList(OperationProcessVo operationProcessVo) {
        startPage();
        //查询库存列表
        List<OperationProcessDto> list = operationProcessService.getList(operationProcessVo);
        return getDataTable(list);
    }

    /**
     * 查看单据
     */
    @RequiresPermissions("productionTube:processmage:processtech:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) throws Exception {
        return AjaxResult.success(operationProcessService.view(id));
    }

    /**
     * 通过线别查询工艺流程列表
     */
    /**
     * 查看单据
     */
    @GetMapping("/getLine")
    public AjaxResult getLine(String productionLineDict) throws Exception {
        return AjaxResult.success(operationProcessService.getLine(productionLineDict));
    }

}
